package org.component 
{
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.geom.Rectangle;
	import org.component.events.ListEvent;
	/**
	 * ...
	 * @author Terry
	 */
	public class ScrollPane 
	{
		
		
		private var _assest:MovieClip = null;
		
		private var _slider:Slider = null;
		
		private var _width:Number = 0;
		
		private var _height:Number = 0;
		
		private var _view:MovieClip = null;
		
		private var _maxHeight:Number = 0;
		
		public function ScrollPane(ui:MovieClip = null, width:Number = 0, height:Number = 0 ) 
		{
			_assest = ui;
			_width = width;
			_height = height;
			initialization();
			
			configEventListeners();
		}
		
		private function initialization():void
		{
			_slider = new Slider(_assest["slider"]);
			
			_view = _assest["view"];
			
			_maxHeight = _view.height;
			
			_view.scrollRect = new Rectangle(0, 0, _width, _height);
			
			var count:int = Math.ceil(_maxHeight / _height);
			
			_slider.update(1,count)
			
		}
		private function configEventListeners():void
		{
			_slider.addEventListener(Event.CHANGE, onChange);
		}
		
		private function onChange(event:Event):void
		{
			var rect:Rectangle = _view.scrollRect;
			rect.y =  _slider.value / 100 * (_maxHeight - _view.scrollRect.height);
			
			_view.scrollRect = rect;
		}
		
		public function get visible():Boolean { return _assest.visible; }
		public function set visible(value:Boolean):void
		{
			_assest.visible = value;
		}
	}

}